﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sekretar.DataLayer;

namespace Sekretar.Repository
{
    public class RDrzava : BaseRepository, InterfaceRepository<DataLayer.Drzava>
    {
        public IQueryable<DataLayer.Drzava> VratiSve()
        {
            dc = new SekretarDataContext();
            return dc.Drzavas;
        }

        public DataLayer.Drzava Nov()
        {
            this.jeNov = true;

            Drzava drzava = new Drzava();
            drzava.Status = true;
            drzava.KorisnikId = Common.Properties.Settings.Default.KorisnikId;
            drzava.DatumRada = Common.Tools.SqlFunkcije.VratiTrenutnoVreme();

            return drzava;
        }

        public DataLayer.Drzava Izmeni(int id)
        {
            return dc.Drzavas.SingleOrDefault(c => c.DrzavaId == id);
        }

        public int Snimi(Drzava drzava)
        {
            if (this.jeNov)
                dc.Drzavas.InsertOnSubmit(drzava);
            dc.SubmitChanges();
            return drzava.DrzavaId;
        }

        public void Brisi(int id)
        {
            dc.Drzavas.DeleteOnSubmit(dc.Drzavas.SingleOrDefault(c => c.DrzavaId == id));
            dc.SubmitChanges();
        }

        
        public IQueryable<DataLayer.Drzava> VratiSveAktivne()
        {
            return dc.Drzavas.Where(t => t.Status == true);
        }
    }
}
